#ifndef WEBSOCKET_DART_H_
#define WEBSOCKET_DART_H_

#include "dart_api_dl.h"
#include <nlohmann/json.hpp>

class DartPort {
private:
    Dart_Port port_;

    // 发送数据的时候，有时候需要等待dart端处理完后，C++才能进行下一步

public:
    DartPort(Dart_Port port) : port_(port) {}
    void send(const std::string& message) {
        Dart_CObject cobj;
        cobj.type = Dart_CObject_kString;
        cobj.value.as_string = const_cast<char *>(message.c_str());
        Dart_PostCObject(port_, &cobj);
    }
    void send(int msgId, const std::string &message) {
        send(msgId, message.c_str());
    }
    void send(int msgId, const char* data) {
        Dart_CObject cobj;
        cobj.type = Dart_CObject_kArray;
        cobj.value.as_array.length = 2;

        Dart_CObject cobj1;
        cobj1.type = Dart_CObject_kInt32;
        cobj1.value.as_int32 = 23;

        Dart_CObject cobj2;
        cobj2.type = Dart_CObject_kString;
        cobj2.value.as_string = const_cast<char*>(data);
        Dart_CObject* cobjarr[2] = {&cobj1, &cobj2};
        
        cobj.value.as_array.values = cobjarr;
        
        Dart_PostCObject_DL(port_, &cobj);
    }
};


#endif